﻿@model ShippingMethodRestrictionModel

<div class="form-horizontal">
    <div class="form-body">
        <div class="form-group">
            <div class="col-md-12 col-sm-12">
                <div class="note note-info">
                    @Loc["Admin.Configuration.Shipping.Restrictions.DescriptionCountry"]
                </div>
                <br/>
                @if (Model.AvailableCountries.Count == 0)
                {
                    <text>No countries defined</text>
                }
                else if (Model.AvailableShippingMethods.Count == 0)
                {
                    <text>No shipping methods available</text>
                }
                else
                {
                    <script>
                        $(document).ready(function () {
                            @foreach (var sm in Model.AvailableShippingMethods)
                            {
                                <text>
                            $('#selectall-@(sm.Id)').click(function () {
                                $('.restrict_@(sm.Id)').prop('checked', $(this).is(':checked')).change();
                            });

                            </text>
                            }
                        });
                    </script>
                    <table class="table table-bordered table-striped table-hover table-hover">
                        <tbody>
                        <tr>
                            <th scope="col">
                                <strong>@Loc["Admin.Configuration.Shipping.Restrictions.Country"]</strong>
                            </th>
                            @foreach (var sm in Model.AvailableShippingMethods)
                            {
                                <th scope="col">
                                    <strong>@sm.Name</strong>
                                    <label class='mt-checkbox mt-checkbox-outline control control-checkbox'>
                                        <input type="checkbox" id="selectall-@(sm.Id)"/>
                                        <div class="control__indicator"></div>
                                    </label>
                                </th>
                            }
                        </tr>
                        @{
                            var altRow = true;
                        }
                        @foreach (var c in Model.AvailableCountries)
                        {
                            altRow = !altRow;
                            <tr class="@(altRow ? "altrowstyle" : "rowstyle")">
                                <td>
                                    <span>@c.Name</span>
                                </td>
                                @foreach (var sm in Model.AvailableShippingMethods)
                                {
                                    var restricted = Model.Restricted.ContainsKey(c.Id) && Model.Restricted[c.Id][sm.Id];
                                    var checkedValue = restricted ? "checked" : null;
                                    <td style="text-align:center">
                                        <label class='mt-checkbox mt-checkbox-outline control control-checkbox'>
                                                <input id="restrict_@(sm.Id)" class="restrict_@(sm.Id)" type="checkbox" value="@(c.Id)" name="restrict_@(sm.Id)" @checkedValue />
                                            <div class="control__indicator"></div>
                                        </label>
                                    </td>
                                }
                            </tr>
                        }
                        </tbody>
                    </table>
                }
            </div>
        </div>
    </div>
</div>